/**
 * 发布订阅者模式
 */
class EventEmit {
    constructor() {
        this.events = {};
    }

    subscribe(name, cb) {
        if (!this.events[name]) {
            this.events[name] = [];
        }
        this.events[name].push(cb);
    }

    unSubscribe(name, cb) {
        if (this.events[name]) {
            this.events[name] = this.events[name].filter((cbItem) => cbItem !== cb);
        }
    }

    notify(name, data) {
        this.events[name].forEach((cb) => cb(data));
    }
}